var Ip="http://120.77.11.13:91"// 优视接口
//var Ip="http://c2.mikeblog.cn"// 优视接口
var IpUrl="http://192.168.1.188"//柚安米接口
$(function() {
	var oTop = $('#goTop');
	var widW = $(window).width(); //窗高度 宽度
	var widH = $(window).height();
	//点击top回到顶部
	oTop.click(function() {
		$('body,html').animate({
			"scrollTop": 0
		}, 500)
	})

	
	// $(".solve .common").on('mouseover',function() {
	// 	var ln = $(this).index();
	// 	$(this).find('span').addClass("solve-on").parents('.common').siblings().find('span').removeClass('solve-on');
	// 	$(this).parents('.solution').find('.text-list').eq(ln).show().siblings('.text-list').hide();
	// });
//首页选择卡
	$(".shouBian-list ul li").on('mouseover',function() {
		var ln = $(this).index();

		$(this).addClass("active").siblings('li').removeClass("active");
		$(this).parents('.shouMain').find('.shouBian-side img').eq(ln).show().siblings('img').hide();
	});


	//焦点
	$('.lay3-name input').focus(function() {
		$(this).css({
			'border': '1px solid #66afe9',
			'boxShadow': '0px 0px 8px #c7e4fa',
			'color': '#333'
		});
		$(this).parent('.lay3-name').find('#shareName').next('.erro').hide();
		$(this).parent('.lay3-name').find('#checkTrade').next('.erro').hide();
		$(this).parent('.lay3-name').find('#checkMobile').next('.erro').hide();
		$('#jionBtn').css({
			'background': '#ff7521',
			'fontSize': '20px',
			'cursor': 'pointer'
		}).val('提交');


	});
	$('.lay3-name input').blur(function() {
		$(this).css({
			'border': '1px solid #ddd',
			'boxShadow': 'none'
		});
	});
	//弹窗
	$.fn.center = function() {
		return this.each(function() {
			var $this = $(this),
				parent = $this.parent(),
				topPos,
				topMargin,
				leftMargin,
				resizeTimeout;
			if (parent.is("body:not(.root-height-set)")) {
				$("html,body").css("height", "100%").addClass("root-height-set");
			}
			if ($this.css("position") === "absolute" || $this.css("position") === "fixed") {
				topPos = "50%";
				topMargin = "-" + Math.round($this.outerHeight() / 2) + "px";
				leftMargin = "-" + Math.round($this.outerWidth() / 2) + "px";
				$this.css({
					"left": "50%",
					"margin-left": leftMargin
				});
			} else {
				topPos = Math.floor((parent.height() - $this.outerHeight()) / 2);
				topMargin = "auto";
				$this.css({
					"position": "relative",
					"margin-left": "auto",
					"margin-right": "auto"
					/*			"top": "50%",
				   "margin-top": topMargin*/
				});
			}
			$this.css({
				"top": topPos,
				"margin-top": topMargin
			});
			$(window).resize(function() {
				if (resizeTimeout) {
					clearTimeout(resizeTimeout);
				}
				resizeTimeout = setTimeout(function() {
					if ($this.css("position") === "absolute") {
						topMargin = "-" + Math.round($this.outerHeight() / 2) + "px";
						leftMargin = "-" + Math.round($this.outerWidth() / 2) + "px";
						$this.css({
							"margin-left": leftMargin,
							"margin-top": topMargin
						});
					} else {
						//topPos=Math.floor((parent.height()-$this.outerHeight())/2);
						//$this.css("top",topPos);
					}
				}, 100);
			});
		});
	}

	//

	function cjSuccess() {
		$('.cjSuccess').css({
			'height': widH + 'px'
		}).show();
		$('.AllBig').center();
		$('.AllBig').show();
	}
	$('.AllBigBnt').click(function() {
		$('.cjSuccess').hide();
		$('.AllBig').hide();
		$('#shareName').val('');
		$('#checkMobile').val('');
		$('#checkTrade').val('');
		window.location.reload();
	});
	$('.AllBig p').click(function() {
		$('.cjSuccess').hide();
		$('.AllBig').hide();
		$('#shareName').val('');
		$('#checkMobile').val('');
		$('#checkTrade').val('');
		window.location.reload();
	});

	//正则

	function shareName() {
		var reg = /^[0-9A-Za-z\u4e00-\u9fa5]{1,14}$/;
		var share = $('#shareName').val();
			//share.replace(/^\s+|\s+$/g, '')
		if (share == "必填") {
			$('#shareName').next('.erro').show().text('请输入您的姓名！');
			return false;
		} else {
			if (!reg.test(share)) {
				$('#shareName').next('.erro').show().text('请输入您的姓名！');
				return false;
			}
		}

		return true;

	}

	function checkTrade() {
		var trade = $('#checkTrade').val();
		var red = /^[0-9A-Za-z\u4e00-\u9fa5]{1,14}$/;
		//trade == '' || trade == null
		if (!red.test(trade)) {
			$('#checkTrade').next('.erro').show().text('请输入您的行业！');
			return false;
		}

		return true;
	}

	function checkMobile() {
		var rex = /^0?(13[0-9]|15[012356789]|18[0-9]|17[0-9])[0-9]{8}$/;
		var mobile = $('#checkMobile').val();

		if (!rex.test(mobile)) {
			$('#checkMobile').next('.erro').show().text('手机号格式错误！');
			return false;
		}

		return true;
	}
	//获取url 参数
	function getArguments() {
	    var url = location.search; //获取url中"?"符后的字串
	    var theRequest = new Object();
	    if(url==''){
	        theRequest=null;
	    }
	    else {
	        if (url.indexOf("?") != -1) {
	            var str = url.substr(1);
	            strs = str.split("&");
	            for (var i = 0; i < strs.length; i++) {
	                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
	            }
	        }
	        else {
	            theRequest = null
	        }
	    }
	    return theRequest;
	}
	
	var channel = '';
	if(getArguments() != null){
	    channel = getArguments().channel;
	    if(channel == null || channel == '' || (channel != 3 && channel != 2)){
	        channel = 1;
	    }
	}else{
	    channel = 1;
	}
	var hrefUrl = window.location.href;
	//接口
	function jionBtn(btn,userName,iPhone,industry){

			$(btn).click(function() {

				var sh = shareName(userName);
				var cm = checkMobile(iPhone);
				var ct = checkTrade(industry);
				if (sh && cm && ct) {
					var param ={
						AppID:'usee_Data_Sync',
						AppSecret:'U2016usee!@#',
						UserName: $(userName).val(),
						Phone: $(iPhone).val(),
						Industry: $(industry).val(),
						NewMediaType:10000,
						SourceUrl:hrefUrl
					}
					$.ajax({
						type: 'post',
						url:Ip+"/c2/client/potential",
						dataType: "json",
						async: true,
						data:JSON.stringify(param),
						beforeSend: function(){
	
							 $(btn).unbind('click');
							
							$(btn).val('正在提交中').css({'background':'#ccc',"cursor": "default"});
						},
						success: function(data) {
	
							//alert(JSON.stringify(data))
							if (data.Status == 1) {
								cjSuccess();

							setTimeout(function(){
									btnHide();
									$('.cjSuccess').hide();
		                       		 window.location.reload();
								},3000)
							} else if (data.Status == 0) {
								//console.log(data.msg)
								
								$(btn).css({
									'background': '#ccc',
									'fontSize': '16px',
									'cursor': 'auto'
								}).text('此信息已提交过了');
							}else{
								alert('提交错误！请重新提交');
								window.location.reload();
							}
						},
						error: function(data) {
							console.log(data)
							//return false;
							alert('提交有误！请重新提交');
						}
					});
				}
			});
	}
	jionBtn("#jionBtn",'#shareName','#checkMobile','#checkTrade');//footer头部提交信息


});